package com.koron.common.core.business.langorguser.service;

import com.koron.bean.base.Response;
import com.koron.bean.system.staff.LangUserOrgConvert;
import com.koron.common.core.business.langorguser.mapper.LangUserOrgConvertMapper;
import com.koron.common.core.util.CodeTools;
import com.koron.common.core.util.FastJsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class LangUserOrgConvertService {


    @TaskAnnotation("exportUserLang")
    public Response exportUserLang(SessionFactory factory, LangUserOrgConvert languserorgconvert) {
        LangUserOrgConvertMapper mapper = factory.getMapper(LangUserOrgConvertMapper.class);

        return Response.success();
    }

    @TaskAnnotation("buildUserLang")
    public Boolean buildUserLang(SessionFactory factory, String acount, String lang, String createAcount) {
        LangUserOrgConvertMapper mapper = factory.getMapper(LangUserOrgConvertMapper.class);

        HashMap<String, String> map = FastJsonUtils.getJsonToBean(lang, HashMap.class);
        Set<String> keySet = map.keySet();
        List<LangUserOrgConvert> insertlist = new ArrayList<>();
        for (String key : keySet) {
            LangUserOrgConvert dbo = new LangUserOrgConvert();
            dbo.setId(CodeTools.getCode32());
            dbo.setUserOrgType("user");
            dbo.setParamId(acount);
            dbo.setLangType(key);
            dbo.setLangValue(map.get(key));
            dbo.setDataSources(createAcount);
            dbo.setCreateTime(new Date());
            insertlist.add(dbo);
        }
        mapper.deleteByParamId(acount);
        mapper.batchInsert(insertlist);
//        for (LangUserOrgConvert langUserOrgConvert : insertlist) {
//            mapper.insert(langUserOrgConvert);
//        }

        return true;
    }


}
